import commonjs from 'rollup-plugin-commonjs'
import {uglify} from 'rollup-plugin-uglify'
import resolve from 'rollup-plugin-node-resolve'
import uglifyJs from 'uglify-js'
import fs from "fs";

let uglifyPlugin = uglify({
    compress:{
        global_defs: {
            "@process.env.NODE_ENV":'"production"'
        },
        drop_console:false,
        drop_debugger:true
    },
    output:{
        beautify: false,
    }
})
let plugins = [
    resolve({
        browser: true
    }),
    commonjs(),
    uglifyPlugin
]
let minifyFiles=[
    {
        input:"src/loader2.js",
        output:"dist/loader2.min.js"
    },{
        input:"src/loader3.js",
        output:"dist/loader3.min.js"
    }
]
for(let entry of minifyFiles){
    var code = fs.readFileSync(entry.input, "utf8");
    var out = uglifyJs.minify(code, {compress: {drop_console: true, drop_debugger: true}, output: {ascii_only: true}}).code
    fs.writeFileSync(entry.output, out)
}

export default [
    {
        input: 'src/compiler.js',
        output: {
            file: 'dist/compiler.min.js',
            name: 'compile',
            format: 'umd',
        },
        plugins: plugins
    }
]
